From 1f99ed0b6a0edc73a40ea5146f52db4bddac201f Mon Sep 17 00:00:00 2001 From: Prabhjyot Singh Sodhi Date: Wed, 25 Mar 2015 02:13:30 +0530 Subject: [PATCH] Adding release flag to cargo test --- src/bin/test.rs | 4 +++- tests/test_cargo_test.rs | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/bin/test.rs b/src/bin/test.rs index 1b09e6d2c..85251624b 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -15,6 +15,7 @@ struct Options { flag_package: Option, flag_target: Option, flag_verbose: bool, + flag_release: bool, } pub const USAGE: &'static str = " @@ -30,6 +31,7 @@ Options: --no-run Compile, but don't run tests -p SPEC, --package SPEC Package to run tests for -j N, --jobs N The number of jobs to run in parallel + --release Build artifacts in release mode, with optimizations --features FEATURES Space-separated list of features to also build --no-default-features Do not build the `default` feature --target TRIPLE Build for the target triple @@ -72,7 +74,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { no_default_features: options.flag_no_default_features, spec: options.flag_package.as_ref().map(|s| &s[..]), exec_engine: None, - release: false, + release: options.flag_release, mode: ops::CompileMode::Test, filter: if tests.is_empty() && bins.is_empty() { ops::CompileFilter::Everything diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 6c08c73ae..0ee882e1c 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -46,6 +46,54 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured RUNNING))); }); +test!(cargo_test_release { + let p = project("foo") + .file("src/lib.rs", r#" + extern crate bar as the_bar; + + pub fn bar() { the_bar::baz(); } + + #[test] + fn foo() { bar(); } + "#) + .file("tests/test.rs", r#" + extern crate foo as the_foo; + + #[test] + fn foo() { the_foo::bar(); } + "#) + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [lib] + name = "bar" + crate_type = ["dylib"] + "#) + .file("bar/src/lib.rs", " + pub fn baz() {} + "); + + assert_that(p.cargo_process("test").arg("-v").arg("--release"), + execs().with_stdout(format!("\ +{compiling} bar v0.0.1 ({dir}) +{running} [..] -C opt-level=3 [..] +{compiling} foo v0.0.1 ({dir}) +{running} [..] -C opt-level=3 [..] +{running} [..] -C opt-level=3 [..] +{running} `[..]target[..]foo-[..]` + +running 1 test +test test_hello ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +", + compiling = COMPILING, dir = p.url(), running = RUNNING))); +}); + test!(cargo_test_verbose { let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) -- 2.30.2